import Vue from 'vue'
import App from './App.vue'

// 导入路由对应组件
import Find from '@/views/Find' // vue文件中，@表示 src目录的绝对路径
import My from '@/views/My'
import Part from '@/views/Part'
import NotFound from '@/views/NotFound'

//二级路由
import Ranking from '@/views/Second/Ranking.vue'
import Recommend from '@/views/Second/Recommend.vue'
import SongList from '@/views/Second/SongList.vue'


Vue.config.productionTip = false

//引入
import VueRouter from 'vue-router'
//注册
Vue.use(VueRouter)
    //配置规则
const routes = [{
        path: '/',
        redirect: '/find'

    }, {
        path: '/find',
        component: Find,
        name: 'Find',
        children: [{
                path: "recommend",
                component: Recommend
            },
            {
                path: "ranking",
                component: Ranking
            },
            {
                path: "songlist",
                component: SongList
            }
        ]


    },
    {
        path: '/my',
        component: My,
        name: 'My'

    },
    {
        path: '/part',
        component: Part,
        name: 'Part'
    },
    {
        path: '/part/:uname',
        component: Part
    },
    {
        path: '*',
        component: NotFound
    },
]

//创建路有对象
const router = new VueRouter({
    routes,
    // mode: 'history'
})

//路由守卫
const isLonge = false
router.beforeEach((to, from, next) => {
    if (to.path === '/my' && !isLonge) {
        next(false)
        alert('11')
    } else {
        next()
    }
})

new Vue({
    router,
    render: (h) => h(App),
}).$mount('#app')